package rs.ac.bg.etf.estudent.fragment;

import java.util.ArrayList;
import java.util.HashMap;

import rs.ac.bg.etf.estudent.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ExamFragment extends Fragment {
	
	private SimpleAdapter mTable;
	private ListView list;
	private View headerView;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_exam, container, false);
		list = (ListView) view.findViewById(R.id.exam_table);
		
		headerView = inflater.inflate(R.layout.exam_list_header, null, false);
		list.addHeaderView(headerView);		
		return view;
	}
	
	@Override
	public void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		
		initList();
		
	}

	private void initList() {
		
		ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("rbr", "1");
		map.put("akronim", "IR4PIA");
		map.put("naziv", "Programiranje internet aplikacija");
		map.put("ngr", "1");
		map.put("tip", "obavezan predmet");
		map.put("poeni", "100");
		map.put("ocena", "10");
		map.put("esbp", "6");
		map.put("rok", "2012/13 septembar");
		map.put("datum", "1.9.2013");
		map.put("prof", "Bosko Nikolic");		
		
		mylist.add(map);
		map = new HashMap<String, String>();
		map.put("rbr", "2");
		map.put("akronim", "IR3SP");
		map.put("naziv", "Sistemsko programiranje");
		map.put("ngr", "1");
		map.put("tip", "obavezan predmet");
		map.put("poeni", "85");
		map.put("ocena","9");
		map.put("esbp", "6");
		map.put("rok", "2012/13 jul");
		map.put("datum", "13.6.2013");
		map.put("prof", "Dragan Bojic");
		mylist.add(map);
		// ...
		mTable = new SimpleAdapter(getActivity(), mylist, R.layout.exam_list_item,
		            new String[] {"rbr", "akronim", "naziv","ngr","tip","poeni","ocena","esbp","rok","datum","prof"},
		            new int[] {R.id.exam_number, R.id.exam_acronym, R.id.exam_title,R.id.exam_ngr,R.id.exam_reg_type,R.id.exam_points,
								R.id.exam_grade,R.id.exam_espb,R.id.exam_month,R.id.exam_date,R.id.exam_profesor});
		list.setAdapter(mTable);
	}

}
